var selectedDataRow = '';
var vueObj = new Vue({
    el: "#vue",
    data: {
        logObj: defLogInfo
    }
});
var isInit = true;

$(function () {
    window.actionEvents = {
        'click .isvInfoView': function(e, value, row, index) {
            //编辑操作
            selectedDataRow = row;
            openCommonIsvPage(row.isvPid, 'checkBizDocApp');
        },
    }
    initTextSearch("#isvName",
        basePath + 'checkApp/checkDocApp/getIsvData?t='+new Date().getTime()+'&isvName=',
        ['isvPid', 'isvName'],
        {'isvPid':'服务商PID', 'isvName':'服务商名称'},
        'isvPid',
        'isvName',
        true,
        selectIsvValue,
        noSelectIsvValue,
        false);
    initTextSearch("#orgName",
        basePath + 'checkApp/checkDocApp/getOrgData?t='+new Date().getTime()+'&orgName=',
        ['orgCode', 'orgName'],
        {'orgCode':'机构编码', 'orgName':'机构名称'},
        'orgCode',
        'orgName',
        true,
        selectOrgValue,
        noSelectOrgValue,
        false);

    laydate.render({
        elem: '#timeInterval'
        ,type: 'datetime'
        ,range: true //或 range: '~' 来自定义分割字符
        // ,value: dateFtt("yyyy-MM-dd hh:mm:ss", preDate) + ' - ' + dateFtt("yyyy-MM-dd hh:mm:ss", curDate)
        //js赋值重置失效，改为就是怕、页面赋值
        ,isInitValue: true //是否允许填充初始值，默认为 true
    });

    laydate.render({
        elem: '#timeInterval1'
        ,type: 'datetime'
        ,range: true //或 range: '~' 来自定义分割字符
        // ,value: dateFtt("yyyy-MM-dd hh:mm:ss", preDate) + ' - ' + dateFtt("yyyy-MM-dd hh:mm:ss", curDate)
        //js赋值重置失效，改为就是怕、页面赋值
        ,isInitValue: true //是否允许填充初始值，默认为 true
    });

    //初始化操作
    if($("#status").val() == 'wait'){
        $("#unCheckDiv").show();
        $("#checkDiv").hide();
        $("#checkTypeDiv").hide();

        $("#detailBtn").hide();
        $("#checkBtn").show();

        $("#unCheckTable").show();
        $("#checkTable").hide();
    }else{
        $("#unCheckDiv").hide();
        $("#checkDiv").show();
        $("#checkTypeDiv").show();

        $("#detailBtn").show();
        $("#checkBtn").hide();

        $("#unCheckTable").hide();
        $("#checkTable").show();
    }
});

function selectIsvValue(data) {
    if (!data || !data.isvPid) {
        return;
    }
    $('#isvPid').val(data.isvPid);
}

function noSelectIsvValue() {
    $('#isvPid').val('');
}

function selectOrgValue(data) {
    if (!data || !data.orgCode) {
        return;
    }
    $('#orgCode').val(data.orgCode);
}

function noSelectOrgValue() {
    $('#orgCode').val('');
}

function formatcheckResultTypeMap(value, row, index) {
    return checkResultTypeMap[value];
}

function doRefresh() {
    selectedDataRow = '';
    if($("#status").val() == 'wait'){
        $('#dataTable').bootstrapTable('refresh', {
            url: basePath + 'checkApp/checkDocApp/pageFindCheckData?t=' + new Date().getTime(),
        });
    }else{
        $('#dataTable1').bootstrapTable('refresh', {
            url: basePath + 'checkApp/checkDocApp/pageFindQueryData?t=' + new Date().getTime(),
        });
    }

}

function changeStatus(value){
    if(value == 'wait'){
        $("#unCheckDiv").show();
        $("#checkDiv").hide();
        $("#checkTypeDiv").hide();
        $("#detailBtn").hide();
        $("#checkBtn").show();

        $("#unCheckTable").show();
        $("#checkTable").hide();
    }else{
        $("#unCheckDiv").hide();
        $("#checkDiv").show();
        $("#checkTypeDiv").show();
        $("#detailBtn").show();
        $("#checkBtn").hide();

        $("#unCheckTable").hide();
        $("#checkTable").show();
    }
    doRefresh();
}

function getParams(params) {
    var docName = $('#docName').val();
    var checkType = $('#checkType').val();
    var orgCode = $('#orgCode').val();
    var bizCode = $('#bizCode').val();
    var isvPid = $('#isvPid').val();
    var status = $.trim($("#status").val());
    var gmtStart = '';
    var gmtEnd = '';
    var timeInterval = '';
    var result = '';
    if(status == 'wait'){
        result = status;
        timeInterval = $("#timeInterval").val();
    }else{
        result = $.trim($("#results").val());
        timeInterval = $("#timeInterval1").val();
    }
    if(timeInterval){
        var dates = timeInterval.split(' - ');
        if(dates && dates.length >1){
            gmtStart = dates[0];
            gmtEnd = dates[1];
        }
    }

    var pageNo = params.pageNumber;
    var pageSize = params.pageSize;
    if (isInit) {
        isInit = false;
        pageSize = defLogInfo.pageSize ? defLogInfo.pageSize : params.pageSize;
        pageNo = defLogInfo.pageNo ? defLogInfo.pageNo : params.pageNumber;
    }
    return {
        docName : docName,
        checkType : checkType,
        orgCode : orgCode,
        bizCode : bizCode,
        isvPid : isvPid,
        result : result,
        beginTimeStr : gmtStart,
        endTimeStr : gmtEnd,
        pageSize : pageSize,
        pageNo : pageNo
    };
}

function openCheckPage() {
    if (!selectedDataRow || selectedDataRow == '') {
        toastr.error(common_no_choose_msg.format("审核"));
        return;
    }
    var tableOptions = $('#dataTable').bootstrapTable('getOptions', null);
    window.location.href = basePath + 'checkApp/checkDocApp/checkDocAppInfoPage?id=' + selectedDataRow.id + '&batchId=' + selectedDataRow.batchId +
        '&hasOrg='+ defLogInfo.hasOrg + '&hasTeam='+ defLogInfo.hasTeam + '&hasApp='+ defLogInfo.hasApp + '&type=check&t=' + new Date().getTime() + '&' + $('#searchForm').serialize() + '&pageNo=' + tableOptions.pageNumber + '&pageSize=' + tableOptions.pageSize;
}

function doReset(formId){
    var status = $("#status").val();
    var formObj = $("#" + formId);
    if(formId && formObj){
        formObj.clearForm(true);
    }
    if(status != 'wait'){
        changeStatus('wait');
    }
}

function openQueryPage() {
    if (!selectedDataRow || selectedDataRow == '') {
        toastr.error(common_no_choose_msg.format("操作"));
        return;
    }
    if (!selectedDataRow.id || selectedDataRow.id == '') {
        toastr.error('所选数据存在问题，请刷新页面重试');
        return;
    }
    var tableOptions = $('#dataTable1').bootstrapTable('getOptions', null);
    window.location.href = basePath + 'checkApp/checkDocApp/checkDocAppInfoPage?id=' + selectedDataRow.id +
        '&hasOrg='+ defLogInfo.hasOrg + '&hasTeam='+ defLogInfo.hasTeam + '&hasApp='+ defLogInfo.hasApp +
        '&batchId=' + selectedDataRow.batchId + '&type=query&t=' + new Date().getTime() + '&' +
        $('#searchForm').serialize() + '&pageNo=' + tableOptions.pageNumber + '&pageSize=' + tableOptions.pageSize;
}

//------------------------------------------------------------------------列表数据初始化

function formatCheckType(value, row, index) {
    if (checkTypeList) {
        for (var i=0; i<checkTypeList.length; i++) {
            if (value == checkTypeList[i].key) {
                return checkTypeList[i].value;
            }
        }
    }
    return value;
}

//------------------------------------------------------------------------列表选中事件
//上边选中事件
$("#dataTable").on("click-row.bs.table",function(e,row,ele){
    $("#dataTable .success").removeClass("success");
    $(ele).addClass("success");
    selectedDataRow = row;
});

$("#dataTable1").on("click-row.bs.table",function(e,row,ele){
    $("#dataTable1 .success").removeClass("success");
    $(ele).addClass("success");
    selectedDataRow = row;
});
